from matplotlib import pyplot as plt
from matplotlib import font_manager

# 准备数据，设置字体
my_font = font_manager.FontProperties(fname="C:\Windows\Fonts\simkai.ttf")
y_3 = [11, 17, 16, 11, 12, 11, 12, 6, 6, 7, 8, 9, 12, 15, 14, 17, 18, 21, 16, 17, 20, 14, 15, 15, 15, 19, 21, 22, 22,
       22, 23]
y_10 = [26, 26, 28, 19, 21, 17, 16, 19, 18, 20, 20, 19, 22, 23, 17, 20, 21, 20, 22, 15, 11, 15, 5, 13, 17, 10, 11, 13,
        12, 13, 6]

# x轴
x_3 = range(1, 32)
x_10 = range(51, 82)

x = list(x_3) + list(x_10)

# 设置图形尺寸
plt.figure(figsize=(20, 8), dpi=80)

# 设置x轴显示
_x_label = ['3月%02d日' % i for i in x_3]
_x_label += ['10月%02d日' % (i - 50) for i in x_10]

plt.xticks(x[::3], _x_label[::3], fontproperties=my_font, rotation=45)

# 绘制
plt.scatter(x_3, y_3, label='三月份')
plt.scatter(x_10, y_10, label='十月份')

# 图例
plt.legend(loc=0, prop=my_font)

# 添加图形描述
plt.xlabel('月份', fontproperties=my_font)
plt.ylabel('温度 单位(℃)', fontproperties=my_font)
plt.title('洛阳市三月份和十月份气温变化图', fontproperties=my_font)

plt.savefig('./04.png')

# 显示
plt.show()
